package homework.test5;

import java.util.Scanner;

/*
使用自定义异常 完成视频中异常的小练习
 */
public class Error {
    public static void main(String[] args) {
        Student stu = new Student();

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名");
        String name = sc.next();
        stu.setName(name);
        while (true){
            System.out.println("请输入年龄：");
            String agestr = sc.next();
            try {
                int age = Integer.parseInt(agestr);
                stu.setAge(age);
                break;
            }catch (NumberFormatException e){
                System.out.println("请输入一个整数");
                continue;
            }catch (AgeOutOfBoundsException e){
                System.out.println(e.toString());
                System.out.println("请输入一个符合范围的年龄");
                continue;
            }
        }

        System.out.println(stu);
    }
}
